'use strict';
const { timeFormater } = require('../utils/tools');
module.exports = app => {
  const { BIGINT, DATE, STRING, INTEGER } = app.Sequelize;
  const User = app.model.define('User', {
    id: {
      type: BIGINT,
      allowNull: false,
      primaryKey: true,
      autoIncrement: true,
      field: 'id',
    },
    nickName: {
      type: STRING(30),
      allowNull: true,
      field: 'nick_name',
    },
    password: {
      type: STRING(30),
      allowNull: true,
      field: 'password',
    },
    status: {
      type: INTEGER(2),
      allowNull: true,
      defaultValue: '1',
      field: 'status',
    },
    phoneNo: {
      type: STRING(20),
      allowNull: false,
      defaultValue: '',
      unique: true,
      field: 'phone_no',
    },
    userType: {
      type: INTEGER(2),
      allowNull: true,
      defaultValue: '1',
      field: 'user_type',
    },
    createdTime: {
      type: DATE,
      allowNull: true,
      field: 'created_time',
      get() {
        return timeFormater(this.getDataValue('createdTime'));
      },
    },
    updatedTime: {
      type: DATE,
      allowNull: true,
      field: 'updated_time',
      get() {
        return timeFormater(this.getDataValue('updatedTime'));
      },
    },
    protocolTime: {
      type: DATE,
      allowNull: true,
      field: 'protocol_time',
      get() {
        return timeFormater(this.getDataValue('protocolTime'));
      },
    },
  }, {
    tableName: 'user',
    timestamps: false,
  });
  // User.associate = () => {
  //   // 基础数据
  //   User.hasMany(app.model.LoginHistory, { as: 'userHistory', foreignKey: 'createId', sourceKey: 'id' });
  // };
  return User;
};
